using UnityEngine;
using System.Collections;

public class CreateGrid
{
    GameObject tableObj = new GameObject("table");

    public GameObject CreateGridColliders(int rows, IBoardDisplay boardDisplay, Player player)
    {	
		tableObj.layer = 2;//ignore raycast
		
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < rows; j++)
            {
				GameObject obj = new GameObject("collider");
				obj.tag = "collider";
				
				var colliderObg = obj.AddComponent<BoxCollider>();
				colliderObg.isTrigger = true;
				obj.transform.parent = tableObj.transform;
				obj.transform.rotation = Quaternion.identity;
				
                var cp = obj.AddComponent<ColliderPosition>();
                cp.SetPosition(j, i);
                cp.player = player;
				
				var collider = obj.GetComponent<BoxCollider>();
				collider.transform.localScale = new Vector3(collider.transform.localScale.x, collider.transform.localScale.y, 0.1f);
				
				Vector3 position = boardDisplay.GetPosition(j, i);
				ScreenToWorld.PositionTransform (obj.transform, (int)position.x, (int)position.y);
				
				Rect size = boardDisplay.GetSize(j, i);
				ScreenToWorld.ScaleCollider (obj, size);
            }
        }
        return tableObj;
    }
}
